package com.jframe.sys.webui;

public class Columns {

	private String field="";
	private String title="";
	private int width=120;
	private int rowspan=1;
	private int colspan=1;
	private String align="center";
	private boolean sortable=false;
	private boolean hidden=false;
	private String formatter="";
	private String editor=null;
	private String data="";
	
	public Columns(){
		
	}
	
	public Columns(String title,int width,String formatter){
		this.field="opt";
		this.title=title;
		this.width=width;
		this.editor=this.getEditjson(new Editor(),field);
		this.formatter=formatter;
	}
	
	public Columns(String field,String title,int width,String data){
		this.field=field;
		this.title=title;
		this.width=width;
		this.editor=this.getEditjson(new Editor(),field);
		this.data=data;
	}
	
	public Columns(String field,String title,int width,Editor editor,String data){
		this.field=field;
		this.title=title;
		this.width=width;
		this.editor=this.getEditjson(editor,field);
		this.data=data;
	}
	
	public Columns(String field,String title,int width,boolean sortable,String data){
		this.field=field;
		this.title=title;
		this.width=width;
		this.sortable=sortable;
		this.editor=this.getEditjson(new Editor(),field);
		this.data=data;
	}
	
	public Columns(String field,String title,int width,boolean sortable,Editor editor,String data){
		this.field=field;
		this.title=title;
		this.width=width;
		this.sortable=sortable;
		this.editor=this.getEditjson(editor,field);
		this.data=data;		
	}
	
	private String getEditjson(Editor editor,String field){
		StringBuffer json = new StringBuffer();
		if(this.formatter.equals("")){
			if(editor.getType().equals("text")){
				json.append("'text'");
			}else if(editor.getType().equals("numberbox")){
				json.append("'numberbox'");
			}else{
				json.append("{type:'");
				json.append(editor.getType());
				json.append("',options:{valueField:'");
				json.append(editor.getValueField());
				json.append("',textField:'");
				json.append(editor.getTextField());
				json.append("',data:");
				json.append(field);
				json.append("s,required:");
				json.append(editor.isRequired());
				json.append("}}");
			}
		}
		return json.toString();
	}
	
	public String getField() {
		return field;
	}
	
	public void setField(String field) {
		this.field = field;
	}
	
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	public int getWidth() {
		return width;
	}
	
	public void setWidth(int width) {
		this.width = width;
	}
	
	public int getRowspan() {
		return rowspan;
	}
	
	public void setRowspan(int rowspan) {
		this.rowspan = rowspan;
	}
	
	public int getColspan() {
		return colspan;
	}
	
	public void setColspan(int colspan) {
		this.colspan = colspan;
	}
	
	public String getAlign() {
		return align;
	}
	
	public void setAlign(String align) {
		this.align = align;
	}
	
	public boolean getSortable() {
		return sortable;
	}
	
	public void setSortable(boolean sortable) {
		this.sortable = sortable;
	}
	
	public boolean isHidden() {
		return hidden;
	}
	
	public void setHidden(boolean hidden) {
		this.hidden = hidden;
	}
	
	public String getFormatter() {
		return formatter;
	}
	
	public void setFormatter(String formatter) {
		this.formatter = formatter;
	}
	
	public String getEditor() {
		return editor;
	}
	
	public void setEditor(Editor editor) {
		this.editor = this.getEditjson(editor,this.getField());
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}
}
